#pragma once
#include "msk1.h"
#include "mskhelper.h"
#include "mskframework.h"

// Foward Declaration
typedef class CMSK1Framework CMSK1Framework;

using namespace std;

class CMSK1Window :
	public virtual IMSK1Window
{
public:
	CMSK1Window(CMSK1Framework* pFramework);
	~CMSK1Window(void);

	STDMETHOD_(ULONG, AddRef());

	STDMETHOD_(ULONG, Release());

	STDMETHOD(QueryInterface)(
		REFIID   riid,
		LPVOID * ppvObj
		);

	STDMETHOD(OnProcessMessage)(
		UINT msg,
		WPARAM wParam,
		LPARAM lParam
		);

	static LRESULT CALLBACK Router(
		HWND hWnd,
		UINT msg,
		WPARAM wParam,
		LPARAM lParam
		);

	static LRESULT CALLBACK StartWindowProc(
		HWND hWnd,
		UINT msg,
		WPARAM wParam,
		LPARAM lParam
		);

	static HRESULT SuperclassWindow(
		LPCWSTR className, 
		LPCWSTR superClassName, 
		CMSK1Window* pWindow
		);

	static HRESULT AddToolTip(
		HWND hWndTarget,
		LPWSTR lpszText,
		BOOL bBallon
		);

	LRESULT HitTestNCA(
		HWND hWnd, 
		const POINT& ptMouse
		);

	STDMETHOD_(void, OnSize(
		UINT nType, 
		int cx, 
		int cy
		));

	STDMETHOD_(void, OnLButtonDown(
		UINT nFlags,
		int x,
		int y
		));

	STDMETHOD_(void, OnMove(
		int x, 
		int y
		));

	STDMETHOD_(void, OnDrawItem(
		LPDRAWITEMSTRUCT lpDIS
		));

	STDMETHOD_(int,	OnCreate(
		LPCREATESTRUCT lpCreateStruct
		));

	STDMETHOD_(void, OnNcCalcSize(
		BOOL bCalcValidRects, 
		NCCALCSIZE_PARAMS* lpncsp
		));

	STDMETHOD_(LRESULT, 
		OnNcHitTest(
		POINT pt
		));

	STDMETHOD_(void, 
		OnNcLButtonDblClk(
		UINT nHitTest,
		LPPOINTS pts
		));

	STDMETHOD_(void, 
		OnActivateApp(
		BOOL bActive,
		DWORD dwThreadID
		));

	STDMETHOD_(void, OnNcPaint(
		HRGN hRgn
		));

	STDMETHOD_(void, OnPaint(
		const PAINTSTRUCT &ps
		));

	STDMETHOD_(void, OnGetMinMaxInfo(
		MINMAXINFO* lpMMI
		));

	STDMETHOD_(void, OnNcMouseMove(
		UINT nHitTest,
		LPPOINTS point
		));

	STDMETHOD_(HINSTANCE, GetModuleInstance());

	STDMETHOD_(HWND, GetWindowHandle());

	STDMETHOD(SetMargin)(
		MSK1_MARGIN_U margin
		);

	STDMETHOD(SetBorder)(
		D2D1_COLOR_F color,
		LONG size
		);

	STDMETHOD_(FLOAT, PixeltoDipX(int x));

	STDMETHOD_(FLOAT, PixeltoDipY(int y));

	STDMETHOD(OnCreateDeviceIndependentResources)();

	STDMETHOD(OnCreateDeviceResources)();

	STDMETHOD_(void, OnDiscardDeviceResources());

	STDMETHOD(PlaceWindow)(
		MSK1_WINDOWPLACEMENT_FLAGS dock
	);

	STDMETHOD(RegisterMessage)(
		IUnknown* ptrClass,
		MSK1_MESSAGE_TYPE msg,
		MSK1_PMF pmf
	);

	CMSK1Framework*				m_pFramework;
	ID2D1SolidColorBrush*		m_d2dBorderColor;
	ID2D1SolidColorBrush*		m_d2dCaptionBarColor;
	ID2D1SolidColorBrush*		m_d2dCaptionTextColor;
	MSK1_WINDOWPLACEMENT_FLAGS	m_wpFlags;
	RECT						m_rcAdjustedWindowRect;
	RECT						m_rcMargin;
	RECT						m_rcMarginOffset;
	HWND						m_hWnd;
	LONG						m_nBorderSize;
	LONG						m_nCaptionHeight;
	LONG						m_nWidth;
	LONG						m_nHeight;
	WNDPROC						m_OldWndProc;

	vector<CMSK1Window*>		m_pvWindows;
	vector<CMSK1Window*>		m_pvWindowsNC;
	STDCALLTHUNK*				m_pThunk;
	LONG						m_cRef;
};

